package com.xiguthings.waka.service.option.impl;

import java.sql.DatabaseMetaData;
import java.util.List;

import com.xiguthings.waka.dao.DataBaseStatus;
import com.xiguthings.waka.dao.mapper.QuestionOptionMapper;
import com.xiguthings.waka.exception.BussinessException;
import com.xiguthings.waka.publicUtils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xiguthings.waka.po.QuestionOption;
import com.xiguthings.waka.po.QuestionOptionExample;
import com.xiguthings.waka.po.extpo.Page;
import com.xiguthings.waka.service.option.IQuestionOptionService;

import javax.annotation.Resource;

@Service
@Transactional
public class QuestionOptionServiceImpl implements IQuestionOptionService {

    @Resource
    QuestionOptionMapper questionOptionMapper;

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public int countByExample(QuestionOptionExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByExample(QuestionOptionExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByPrimaryKey(String id) throws Exception {
        int row = questionOptionMapper.deleteByPrimaryKey(id);
        return row;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insert(QuestionOption t) throws Exception {
        if (t == null) {
            BussinessException.throwThis(CODE_EMPTY_REQUIRED, null);
        }

        if (StringUtils.isBlank(t.getQuestionId())) {
            BussinessException.throwThis(CODE_EMPTY_REQUIRED, "questionId为空，问题选项必须制定所属的试题");
        }


        String id = StringUtils.getRandomUUID();
        t.setOptionId(id);
//        t.setStatus(DataBaseStatus.NORMAL);
        int row = questionOptionMapper.insert(t);
        return row;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insertSelective(QuestionOption t) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<QuestionOption> selectByExample(QuestionOptionExample example) throws Exception {
        return questionOptionMapper.selectByExample(example);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public QuestionOption selectByPrimaryKey(String id) throws Exception {
        QuestionOption questionOption = questionOptionMapper.selectByPrimaryKey(id);
        return questionOption;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExampleSelective(QuestionOption t, QuestionOptionExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExample(QuestionOption t, QuestionOptionExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKeySelective(QuestionOption t) throws Exception {
        questionOptionMapper.updateByPrimaryKeySelective(t);
        return questionOptionMapper.updateByPrimaryKeySelective(t);
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKey(QuestionOption t) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page selectByPage(Page pageEntity, QuestionOptionExample example) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

}
